package cn.com.connext.scrm.service;

import cn.com.connext.scrm.domain.master.BrowseRecordActivity;
import cn.com.connext.scrm.repository.master.BrowseRecordActivityRepository;
import cn.com.connext.scrm.service.mapper.BrowseRecordActivityService;
import cn.com.connext.scrm.web.rest.req.BrowseRecordReq;
import cn.com.connext.scrm.web.rest.resp.BrowseRecordResp;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.time.ZonedDateTime;

@Service
public class BrowseRecordActivityServiceImpl implements BrowseRecordActivityService {

    @Autowired
    private BrowseRecordActivityRepository browseRecordActivityRepository;

    @Override
    public BrowseRecordResp saveBrowseRecord(BrowseRecordReq req) {
        BrowseRecordResp browseRecordResp = new BrowseRecordResp();
        BrowseRecordActivity browseRecordActivity = new BrowseRecordActivity();
        if (null == req) {
            return browseRecordResp;
        }
        BeanUtils.copyProperties(req, browseRecordActivity);
        browseRecordActivity.setCreateTime(ZonedDateTime.now());
        browseRecordActivity = browseRecordActivityRepository.saveAndFlush(browseRecordActivity);
        if (null == browseRecordActivity) {
            return browseRecordResp;
        }
        BeanUtils.copyProperties(browseRecordActivity, browseRecordResp);
        return browseRecordResp;
    }
}
